$('form').on('submit', function (e) {
    e.preventDefault()
    $.ajax({
        url: '/my/user/updatepwd',
        type: 'POST',
        data: $(this).serialize(),
        success: function (res) {
            if (res.status === 0) {
                localStorage.removeItem('token')
                window.parent.location.href = '../login.html'
            } else {
                layer.msg(res.message)
            }
        }
    })
})

// 表单验证
let form = layui.form
form.verify({
    len: [/^\S{6,12}/, '密码长度为6-12位，不能有空格'],
    dif: function (val) {
        if (val === $('.oldpwd').val()) {
            return '新密码不能与原密码一致'
        }
    },
    same: function (val) {
        if (val !== $('.newpwd').val()) {
            return '两次密码不一致'
        }
    }
})